package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.CompanyEmpNecessaryAddDTO;
import org.jsola.hr.dto.CompanyEmpNecessaryUpdateDTO;
import org.jsola.hr.entity.CompanyEmpNecessaryDO;
import org.jsola.hr.query.CompanyEmpNecessaryQuery;
import org.jsola.hr.service.ICompanyEmpNecessaryService;
import org.jsola.hr.vo.CompanyEmpNecessaryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 公司员工必填模块信息
 *
 * @author zhr
 */
@Component
public class CompanyEmpNecessaryTestHelper extends BaseTestHelper {
    
    @Autowired
    private ICompanyEmpNecessaryService companyEmpNecessaryService;

    /**
     * 生成add测试数据
     * @return CompanyEmpNecessaryAddDTO
     */
    public CompanyEmpNecessaryAddDTO getCompanyEmpNecessaryAddDTO(){
        CompanyEmpNecessaryAddDTO companyEmpNecessaryAddDTO = new CompanyEmpNecessaryAddDTO();
        companyEmpNecessaryAddDTO.setModuleName(getRandomValue("varchar",50));
        companyEmpNecessaryAddDTO.setModuleCode(getRandomValue("varchar",30));
        companyEmpNecessaryAddDTO.setIsNecessary(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        companyEmpNecessaryAddDTO.setCompanyId(getRandomValue("varchar",32));
        return companyEmpNecessaryAddDTO;
    }


    /**
     * 生成update测试数据
     * @return CompanyEmpNecessaryUpdateDTO
     */
    public CompanyEmpNecessaryUpdateDTO getCompanyEmpNecessaryUpdateDTO(CompanyEmpNecessaryVO companyEmpNecessaryVO){
        return companyEmpNecessaryService.selectDOById(companyEmpNecessaryVO.getId(), SITE_ID).to(CompanyEmpNecessaryUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return CompanyEmpNecessaryQuery
     */
    public CompanyEmpNecessaryQuery getCompanyEmpNecessaryQuery() {
        CompanyEmpNecessaryQuery companyEmpNecessaryQuery = new CompanyEmpNecessaryQuery();
        List<CompanyEmpNecessaryDO> companyEmpNecessaryDOList = companyEmpNecessaryService.list(new CompanyEmpNecessaryDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(companyEmpNecessaryDOList)) {
            CompanyEmpNecessaryDO companyEmpNecessaryDO = companyEmpNecessaryDOList.get(0);
            companyEmpNecessaryQuery = companyEmpNecessaryDO.to(CompanyEmpNecessaryQuery.class);
        }
        return companyEmpNecessaryQuery;
    }

    /**
     * 保存示例
     * @return CompanyEmpNecessaryVO
     */
    public CompanyEmpNecessaryVO saveCompanyEmpNecessaryExample(){
        CompanyEmpNecessaryAddDTO addDTO = this.getCompanyEmpNecessaryAddDTO();
        CompanyEmpNecessaryVO companyEmpNecessaryVO = companyEmpNecessaryService.save(addDTO,buildTokenUser());
        return companyEmpNecessaryVO;
    }


}

